#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
int is_year(int year)
{
	if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
		return 1;
	return 0;
}

int main()
{
	int year = 0;
	int month = 0;
	while (scanf("%4d %2d", &year, &month) != EOF)
	{
		int monthx[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		if (is_year(year) == 1)
			monthx[1] = 29;
		printf("%d\n", monthx[month - 1]);
	}
	
	return 0;
}
/*int main()
{
	float a = 1;
	float b = 1;
	float c = 1;
	while(scanf("%f %f %f", &a, &b, &c)!=EOF)
	{
		if (a == 0)
			printf("Not quadratic equation");
		else
		{
			if (pow(b, 2) > a * c * 4)
				printf("x1=%.2f;x2=%.2f", (-1 * b - pow(pow(b, 2) - 4 * a * c, 1.0 / 2)) / (2 * a), (-1 * b + pow(pow(b, 2) - 4 * a * c, 1.0 / 2)) / (2 * a));
			else if (pow(b, 2) == a * 4 * c)
			{
				if (b / (a * 2) == 0)
					printf("x1=x2=0.00");
				else
					printf("x1=x2=%.2f", -1 * b / (a * 2));
			}
			else
			{
				float num1 = (-1) * b / (2 * a);
				float num2 = sqrt(4 * a * c - pow(b, 2)) / (2 * a);
				printf("x1=%.2f-%.2fi;x2=%.2f+%.2fi", num1, num2, num1, num2);
			}
		}
		printf("\n");
	}
	return 0;
}*/
//(-1*b+/-pow(pow(b,2)-4*a*c))/(2*a*c)
//-1*b/(a*c*2)